// Mock工具函数
const Mock = require("mockjs");

// 创建成功响应
function createSuccessResponse(data = {}) {
  return {
    code: 200,
    message: 'success',
    data,
  };
}

// 创建错误响应
function createErrorResponse(message = 'error', code = 500) {
  return {
    code,
    message,
    data: null,
  };
}

// 创建分页响应
function createPageResponse(list = [], total = 0, page = 1, pageSize = 10) {
  return {
    code: 200,
    message: 'success',
    data: {
      list,
      total,
      page,
      pageSize,
      hasMore: page * pageSize < total,
    },
  };
}

// 解析URL参数
function parseUrlParams(url) {
  const params = {};
  const queryString = url.split('?')[1];
  if (queryString) {
    queryString.split('&').forEach(param => {
      const [key, value] = param.split('=');
      params[key] = decodeURIComponent(value);
    });
  }
  return params;
}

module.exports = {
  createSuccessResponse,
  createErrorResponse,
  createPageResponse,
  parseUrlParams,
};
